?><?
function ping_wo_wait($server,$path){
  if(strpos($server,":")!==false)$server=substr($server,0,strpos($server,":"));
  $errno=0;
  $errstr="";
  $fp = fsockopen($server, 80, $errno, $errstr, 30);
  if($fp){
    $out = "GET $path HTTP/1.0\r\n";
    $out .= "Host: $server\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fputs($fp, $out);
    fclose($fp);    
  }
  return $errstr;
}
function ping_w_wait($server,$path){
  if(strpos($server,":")!==false)$server=substr($server,0,strpos($server,":"));
  $errno=0;
  $errstr="";
  $fp = fsockopen($server, 80, $errno, $errstr, 30);
  if($fp){
    $out = "GET $path HTTP/1.0\r\n";
    $out .= "Host: $server\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fputs($fp, $out);
    while (!feof($fp)) {
        $errstr.=fgets($fp, 128);
    }
    fclose($fp);
  }
  $result=array();
  $result=explode("\r\n\r\n",$errstr);
  if(isset($result[0])){
    $result["header"]=$result[0];
  }
  if(isset($result[1])){
    $result["content"]=$result[1];
  }
  return $result;
}
function inet_set_headers($path,$server,$content){

}

function post_w_wait($server,$path,$data=array()){
  $errno=0;
  $errstr="";
  $fp = @fsockopen($server, 80, $errno, $errstr, 30);
  if(!$fp)return "";
  $content="";
  $first=true;
  foreach($data as $key=>$value){
    $content.=!$first?"&":"";$first=false;
    $content.="$key=".urlencode($value);
  }
  if($fp){
    $out  = "POST $path HTTP/1.0\r\n";
    $out .= "User-Agent: Grape Cms [admin@grapecms.ru] \r\n";
    $out .= "Host: $server\r\n";
    $out .= "Referer: http://$server";
    $out .= "Connection: Close\r\n";
    $out .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $out .= "Content-Length: ".strlen($content)."\r\n\r\n";
    $out .= "$content";

    fputs($fp, $out);
    while (!feof($fp)) {
        $errstr.=fgets($fp, 128);
    }
    fclose($fp);
  }
  return $errstr;
}

function post_wo_wait($server,$path,$data=array()){
  $errno=0;
  $errstr="";
  $fp = @fsockopen($server, 80, $errno, $errstr, 30);
  if(!$fp)return "";
  $content="";
  $first=true;
  foreach($data as $key=>$value){
    $content.=!$first?"&":"";$first=false;
    $content.="$key=".urlencode($value);
  }
  if($fp){
    $out  = "POST $path HTTP/1.0\r\n";
    $out .= "User-Agent: Grape Cms [admin@grapecms.ru] \r\n";
    $out .= "Host: $server\r\n";
    $out .= "Referer: http://$server";
    $out .= "Connection: Close\r\n";
    $out .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $out .= "Content-Length: ".strlen($content)."\r\n\r\n";
    $out .= "$content";

    fputs($fp, $out);
    fclose($fp);
  }
  return "";
}
